import requests,os,json,pytest,csv,logging,allure,time
from dotenv import load_dotenv
from utils import data_parametrize


# 加载.env文件
load_dotenv()
t = time.strftime('%Y%m%d%H%M%S')

class Test_wms():
    # 登录
    @pytest.mark.parametrize('wms_data', data_parametrize.load_csv(r'D:\zhuanwu\2301A_lianxi\data\login.csv'))
    def test_01_login(self,wms_data):
        logging.info('-----------------begin-------------------')
        login = requests.post(url='http://10.59.9.32/jeewms/loginController.do?checkuser',
                              headers={'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
                                       'cookie': 'JSESSIONID=090405F87BF588A8D7CA9CF066FC4843; JEECGINDEXSTYLE=ace'},
                              data={'userName': wms_data['username'], 'password': wms_data['password'],
                                    'randCode': '0406', 'langCode': 'zh-cn'})
        # print(login.json())
        print('响应结果：\n', json.dumps(login.json(), indent=4, ensure_ascii=False))
        print(login.json()['msg'], wms_data.get('expect'))
        assert wms_data.get('expect') == login.json()['msg']
        logging.info('-----------------end-------------------')
        allure.attach.file(
            # 要附加的文件路径
            fr'D:\zhuanwu\2301A_lianxi\log\{t}.log',
            # 报告中日志呈现的名字（可以随便起名）
            name=f"aaa.log",
            # 附件的类型
            attachment_type=allure.attachment_type.TEXT
        )

    # 月台定义——录入
    # @pytest.mark.parametrize('wms_data',data_parametrize.load_yaml(r'D:\zhuanwu\2301A_lianxi\data\manage.yaml'))
    # def test_02_month(self,wms_data):
    #     manage = requests.post(url='http://10.59.9.32/jeewms/baPlatformController.do?doAdd',
    #                            headers={'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
    #                                     'cookie': 'JSESSIONID=FD35133FB9F5DBD3B82BCE15E558D248; JEECGINDEXSTYLE=ace'},
    #                            json={'platformCode':wms_data.get('platformCode'),'platformName':wms_data['platformName']})
    #     print(manage.json())
    #     assert manage.json()['msg'] == wms_data.get('expect')















